package com.taotao.item.controller;

import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

@Controller
public class HtmlGenController {
    @Autowired
    private FreeMarkerConfigurer configurer;
    @RequestMapping("/genHtml")
    @ResponseBody
    public String gen() throws Exception{
        //生成静态页面
        Configuration configuration = configurer.getConfiguration();
        Template template = configuration.getTemplate("template.ftl");
        Map model = new HashMap();
        model.put("springtestkey","hello");
        Writer writer = new FileWriter(new File("i:/freemarker/hello.html"));
        template.process(model,writer);
        writer.close();

        return "ok";
    }
}
